﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Business_Logic_Layer;

namespace Money_Dance
{
    public partial class UserControlTransactionRemiderSaving : UserControl
    {
        BUSS Buss = new BUSS();  
        DateTime date = DateTime.Now;
        public static string AccountType;
        public static int UserID;
        public string TypeDate="Date";
        public string values;
        public int Auto;
        public string Repeatvalues = "0";
        public string RepeatSeed = "0";

        public UserControlTransactionRemiderSaving()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Constructor UserControlTransactionRemiderSaving.
        /// </summary>
        /// <param name="AccID"></param>
        /// <param name="UserId"></param>
        public UserControlTransactionRemiderSaving(string AccID, int UserId)
        {
            AccountType = AccID;
            UserID = UserId;
        }
        private void UserControlTransactionRemiderSaving_Load(object sender, EventArgs e)
        {
            // Đưa dữ liệu danh mục trong bảng Category ra Combobox.
            CbxCategory.DataSource = Buss.Categories();
            CbxCategory.DisplayMember = "NAME";
            CbxCategory.ValueMember = "NAME";
            // Điều chỉnh DatagridviewChecking theo các cột.
            dataGridViewChecking.AutoGenerateColumns = false;
            dataGridViewChecking.AlternatingRowsDefaultCellStyle.BackColor = Color.Blue;
            // Thể hiện lịch nhắc nhở.
            dataGridViewChecking.DataSource = Buss.TransReminder(UserID, cbxType.Text);                        
            tbxStartDay.Text = date.ToShortDateString();
        }

        private void TbxSoTienChi_Click(object sender, EventArgs e)
        {
            TbxSoTienChi.Clear();
            TbxSoTienThu.Text = "0";
        }

        private void TbxSoTienThu_Click(object sender, EventArgs e)
        {
            TbxSoTienThu.Clear();
            TbxSoTienChi.Text = "0";
        }

        private void btn_Capnhat_Click(object sender, EventArgs e)
        {
            // Thiết lập các điều kiện cho trước sự kiện cập nhật.
            if (tbxDay.Text != "")
            {
                RepeatSeed = tbxDay.Text;
            }
            if (cbxType.Text == "")
            {
                MessageBox.Show("chon tai khoan giao dich");
                return;
            }
            if (TbxSoTienChi.Text == "")
                TbxSoTienChi.Text = "0";
            if (TbxSoTienThu.Text == "")
                TbxSoTienThu.Text = "0";
            if (RepeatSeed == "")
                RepeatSeed = "0";   
            if (Repeatvalues != "0")
            {           
                Repeatvalues = Repeatvalues.Substring(1, Repeatvalues.Length - 2);
            }           
            // Insert dữ liệu vào trong bảng Timerule và TransacionReminder.
            Buss.InsertTimerule(tbxStartDay.Text, tbxEndDay.Text, TypeDate, Repeatvalues, int.Parse(RepeatSeed));
            Buss.InsertTransReminder(Buss.GetIdAccount(UserID, cbxType.Text), double.Parse(TbxSoTienThu.Text), double.Parse(TbxSoTienChi.Text), Buss.GetIdCategory(CbxCategory.Text), txDbescription.Text, Auto, (int)Buss.GetIDTimer());
            // Show dữ liệu lịch nhắc theo từng user.
            dataGridViewChecking.DataSource = Buss.TransReminder(UserID, AccountType);
            Repeatvalues = "0";
            txDbescription.Text = "";
        }    

        private void tabDaily_Click(object sender, EventArgs e)
        {
            TypeDate = "Date";
            Repeatvalues = "0";
            RepeatSeed = "0";
        }

        private void tabweedly_Click(object sender, EventArgs e)
        {
            TypeDate = "weedly";
        }

        private void tabmonthly_Click(object sender, EventArgs e)
        {
            Repeatvalues = "0";
            TypeDate = "Month";
            RepeatSeed = "0";
        }

        private void tabAnnually_Click(object sender, EventArgs e)
        {
            TypeDate = "Annually";
        }

        // Kiểm tra checkbox tự động đăng nhập.
        private void Commit_CheckedChanged(object sender, EventArgs e)
        {
            if (ChbCommit.Checked == true)
                Auto = 1;
            else
                Auto = 0;
        }

        // Kiểm tra ngày trong tháng có được check hay không dựa trên Checkbox.
        private void st1_CheckedChanged(object sender, EventArgs e)
        {
            if (st1.Checked == true)
                Repeatvalues = Repeatvalues+st1.Text + ",";         
        }

        private void st2_CheckedChanged(object sender, EventArgs e)
        {
            if (st2.Checked == true)
                Repeatvalues = Repeatvalues + st2.Text + ","; ;      
        }

        private void st3_CheckedChanged(object sender, EventArgs e)
        {
            if (st3.Checked == true)
                Repeatvalues = Repeatvalues + st3.Text + ","; ;           
        }

        private void st4_CheckedChanged(object sender, EventArgs e)
        {
            if (st4.Checked == true)
                Repeatvalues = Repeatvalues + st4.Text + ","; ;              
        }

        private void st5_CheckedChanged(object sender, EventArgs e)
        {
            if (st5.Checked == true)
                Repeatvalues = Repeatvalues + st5.Text + ","; ;   
        }

        private void st6_CheckedChanged(object sender, EventArgs e)
        {
            if (st6.Checked == true)
                Repeatvalues = Repeatvalues + st6.Text + ","; ;   
           
        }

        private void st7_CheckedChanged(object sender, EventArgs e)
        {
            if (st7.Checked == true)
                Repeatvalues = Repeatvalues + st7.Text + ","; ;              
        }

        private void st8_CheckedChanged(object sender, EventArgs e)
        {
            if (st8.Checked == true)
                Repeatvalues = Repeatvalues + st8.Text + ","; ;   
        }

        private void st9_CheckedChanged(object sender, EventArgs e)
        {
            if (st9.Checked == true)
                Repeatvalues = Repeatvalues + st9.Text + ","; ;             
        }

        private void st10_CheckedChanged(object sender, EventArgs e)
        {
            if (st10.Checked == true)
                Repeatvalues = Repeatvalues + st10.Text + ",";           
        }

        private void st11_CheckedChanged(object sender, EventArgs e)
        {
            if (st11.Checked == true)
                Repeatvalues = Repeatvalues + st11.Text + ",";           
        }

        private void st12_CheckedChanged(object sender, EventArgs e)
        {
            if (st12.Checked == true)
                Repeatvalues = Repeatvalues + st12.Text + ",";
        }

        private void st13_CheckedChanged(object sender, EventArgs e)
        {
            if (st13.Checked == true)
                Repeatvalues = Repeatvalues + st13.Text + ",";            
        }

        private void st14_CheckedChanged(object sender, EventArgs e)
        {
            if (st14.Checked == true)
                Repeatvalues = Repeatvalues + st14.Text + ",";         
        }

        private void st15_CheckedChanged(object sender, EventArgs e)
        {
            if (st15.Checked == true)
                Repeatvalues = Repeatvalues + st15.Text + ",";
           
        }

        private void st16_CheckedChanged(object sender, EventArgs e)
        {
            if (st16.Checked == true)
                Repeatvalues = Repeatvalues + st16.Text + ",";
         
        }

        private void st17_CheckedChanged(object sender, EventArgs e)
        {
            if (st17.Checked == true)
                Repeatvalues = Repeatvalues + st17.Text + ",";
          
        }

        private void st18_CheckedChanged(object sender, EventArgs e)
        {
            if (st18.Checked == true)
                Repeatvalues = Repeatvalues + st18.Text + ",";
          
        }

        private void st19_CheckedChanged(object sender, EventArgs e)
        {
            if (st19.Checked == true)
                Repeatvalues = Repeatvalues + st19.Text + ",";
           
        }

        private void st20_CheckedChanged(object sender, EventArgs e)
        {
            if (st20.Checked == true)
                Repeatvalues = Repeatvalues + st20.Text + ",";
            
        }

        private void st21_CheckedChanged(object sender, EventArgs e)
        {
            if (st21.Checked == true)
                Repeatvalues = Repeatvalues + st21.Text + ",";
        }

        private void st22_CheckedChanged(object sender, EventArgs e)
        {
            if (st22.Checked == true)
                Repeatvalues = Repeatvalues + st22.Text + ",";
        }

        private void st23_CheckedChanged(object sender, EventArgs e)
        {
            if (st23.Checked == true)
                Repeatvalues = Repeatvalues + st23.Text + ",";
        }

        private void st24_CheckedChanged(object sender, EventArgs e)
        {
            if (st24.Checked == true)
                Repeatvalues = Repeatvalues + st24.Text + ",";
           
        }

        private void st25_CheckedChanged(object sender, EventArgs e)
        {
            if (st25.Checked == true)
                Repeatvalues = Repeatvalues + st25.Text + ",";
        }

        private void st26_CheckedChanged(object sender, EventArgs e)
        {
            if (st26.Checked == true)
                Repeatvalues = Repeatvalues + st26.Text + ",";
            
        }

        private void st27_CheckedChanged(object sender, EventArgs e)
        {
            if (st27.Checked == true)
                Repeatvalues = Repeatvalues + st27.Text + ",";
          
        }

        private void st28_CheckedChanged(object sender, EventArgs e)
        {
            if (st28.Checked == true)
                Repeatvalues = Repeatvalues + st28.Text + ",";      
        }

        private void st29_CheckedChanged(object sender, EventArgs e)
        {
            if (st29.Checked == true)
                Repeatvalues = Repeatvalues + st29.Text + ",";
        }

        private void st30_CheckedChanged(object sender, EventArgs e)
        {
            if (st30.Checked == true)
                Repeatvalues = Repeatvalues + st30.Text + ",";
        }

        private void st31_CheckedChanged(object sender, EventArgs e)
        {
            if (st31.Checked == true)
                Repeatvalues = Repeatvalues + st31.Text + ",";
        }

        private void comType_SelectedIndexChanged(object sender, EventArgs e)
        {
            dataGridViewChecking.DataSource = Buss.TransReminder(UserID, cbxType.Text);
        }

        private void panel3_Paint(object sender, PaintEventArgs e)
        {
            TypeDate = "Month";           
        }
    }
}
